﻿var Sys_ErrorLogList;
var Sys_ErrorLogStore;
var Sys_ErrorLogTreeStore;
var Sys_ErrorLogParentId
// 功能模块grid展示
Sys_ErrorLogList = function (id) {
    Sys_ErrorLogParentId = id;
    var url = "/Manager/Sys_ErrorLog/List/" + id;
    var ModuleEdtId = 0;
    //grid 填充
    Ext.define('Sys_ErrorLogGridModel', {
        extend: 'Ext.data.Model',
        fields: [
            { name: "conent", type: "string" }
            ]
    });

    //grid获取 json数组
    Sys_ErrorLogStore = Ext.create('Ext.data.Store', {
        pageSize: CMN.pageSize,
        model: 'Sys_ErrorLogGridModel',
        buffered: false,
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: url,
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        },
         autoLoad: true,
        sorters: [{
            property: 'conent',
            direction: 'DESC'
        }]
    });

    //分页设置
    var pagingBar = Ext.create('Ext.PagingToolbar', {
        displayInfo: true, emptyMsg: "没有数据显示", displayMsg: "显示从{0}条数据到{1}条数据，共{2}条数据",
        store: Sys_ErrorLogStore,
        pageSize: CMN.pageSize,
        //显示右下角信息
        prevText: "上一页",
        nextText: "下一页",
        refreshText: "刷新",
        lastText: "最后页",
        firstText: "第一页",
        beforePageText: "当前页",
        afterPageText: "共{0}页"
    });





    //grid配置
    var grid = Ext.create('Ext.grid.Panel', {
        //renderTo: "Sys_ErrorLogGrid",
        //contentEl: 'Sys_ErrorLogGrid',
        layout: "fit",
        alias: 'widget.methodPanel',
        columnLines: true,
        loadMask: true,
        frame: true,
        height: Ext.get("MainTab").getHeight() - 30,
        width: Ext.get("MainTab").getWidth() - 180,
        //            border: false,
        viewConfig:{
   enableTextSelection:true
},
        autoScroll: true,
        store: Sys_ErrorLogStore,
        //            ds: Sys_ErrorLogStore,
        //            //sm: sm,
        //            columnLines: true,
        //            //cm: cm2,
        //            viewConfig: {
        //                stripeRows: true,
        //                trackOver: true,
        //                emptyText: '<div style="color:#999;margin:5px;">当前没有记录显示<div>'
        //            },
        //            stripeRows: true,
        scroll: "both",
        bbar: pagingBar,
        columns: [
        //Ext.create('Ext.grid.RowNumberer'),
                {header: "内容", dataIndex: "conent", width: (Ext.get("MainTab").getWidth() - 280) }

             ]

    });


    // tree start create('Ext.Viewport'

    Sys_ErrorLogTreeStore = Ext.create('Ext.data.TreeStore', {
        fields: ['text'],
        proxy: {
            type: 'ajax',
            url: '/Manager/Sys_ErrorLog/FileList'
        },
        root: {
            text: '系统错误日志列表',
            expanded: true
        },
        folderSort: true,
        sorters: [{
            property: 'text',
            direction: 'desc'
        }]
    });

    var tree = Ext.create('Ext.tree.Panel', {
        region: 'west',
        store: Sys_ErrorLogTreeStore,
        contentEl: 'treeSys_ErrorLog',
        split: true,
        border: true,
        collapsible: false,
        columnWidth: 1 / 5,
        width: 200,
        height: Ext.get("MainTab").getHeight() - 30,
        minSize: 100,
        maxSize: 260,
        listeners: {
            'itemclick': function (view, node) {
                if (node.data.text != "") {
                    Sys_ErrorLogParentId = node.data.text;
                    url = "/Manager/Sys_ErrorLog/List/" + node.data.text;
                    Sys_ErrorLogStore.proxy.url = url;
                    Sys_ErrorLogStore.loadPage(1);
                }

            }
        },
        dockedItems: [{
            xtype: 'toolbar',
            items: ['-', {
                text: '删除',
                tooltip: "删除",
                iconCls: "deleteicon",
                handler: function () {
                    var records = tree.getView().getChecked(),
                        names = [];

                    Ext.Array.each(records, function (rec) {
                        names.push(rec.get('text'));
                    });

                    Ext.MessageBox.show({
                        title: 'Selected Nodes',
                        msg: names.join('<br />'),
                        icon: Ext.MessageBox.INFO
                    });
                    console.log(names);
                    if (names.length == 0) {
                        Ext.Msg.alert("提示信息", "请您至少选择一个!");
                    }
                    else {

                        //Ext.Msg.alert("提示信息", "对不起只能选择一个!");
                        Ext.Msg.confirm("提 示!", "您确定要删除" + names.join(',') + "吗?", function (btn) {
                            if (btn == "yes") {
                                Ext.Ajax.request({
                                    url: "/Manager/Sys_ErrorLog/Delete/" + names.join(','),
                                    method: "get",
                                    success: function (d) {
                                        //成功后
                                        var action = Ext.JSON.decode(d.responseText);
                                        //alert(action.success);
                                        var flag = action.success;
                                        if (flag == "true") {
                                            Sys_ErrorLogTreeStore.load();
                                            Ext.MessageBox.alert("恭喜", "删除成功!");
                                        }
                                        else {
                                            var message = action.message;
                                            if (message) {
                                                Ext.MessageBox.alert("删除失败!", message);
                                            }
                                            else {
                                                Ext.MessageBox.alert("提示!", "删除失败!");
                                            }
                                        }
                                    },
                                    failure: function (form, action) {
                                        Ext.MessageBox.alert("提示!", "修改失败!");
                                    }
                                })
                            }
                            else {

                            }
                        })

                    }

                }
            }
                    , '-']
        }]
    });

    // tree end

    //tree.render();

    var tabpanel1 = Ext.create('Ext.tab.Panel', {
        height: Ext.get("MainTab").getHeight() - 30,
        width: Ext.get("MainTab").getWidth() - 180,
        id: "tabpanel1",
        items: [{
            id: "tab1",
            title: 'Bogus Tab',
            html: 'Hello world 1'
        }]

    });

    var panel = Ext.create('Ext.Panel', {
        baseCls: 'x-plain',
        renderTo: "Sys_ErrorLogTop",
        margins: '35 5 5 0',
        layout: {
            type: 'table',
            columns: 2
        },
        // applied to child components
        defaults: { frame: true, layout: 'anchor',
            defaults: {
                anchor: '100%'
            }
        },
        items: [
            tree, grid

            ]
    });
    Sys_ErrorLogStore.loadPage(1);

}
    Sys_ErrorLogList(0);
